#include <algorithm>
#include <iostream>
using namespace std;
#include <vector>

class Solution
{
public:
    static string multiply(string num1, string num2)
    {
        string rs;
        int m = num1.size();
        int n = num2.size();
        vector<int> tmp(m+n-1);
        reverse(num1.begin(), num1.end());
        reverse(num2.begin(), num2.end());

        for(int i=0; i<n; i++)
        {
            for(int j=0; j<m; j++)
            {
                tmp[i+j] += (num2[i]-'0')*(num1[j]-'0');
            }
        }
        int t = 0, i = 0;//t既是进位也是加进位之后的值
        while(i<tmp.size() || t)
        {
            if(i<tmp.size())
                t += tmp[i++];
            rs += t%10+'0';
            t /= 10;
        }

        while(rs.size()>1 && rs.back()=='0')
        {
            rs.pop_back();
        }
        reverse(rs.begin(), rs.end());
        return rs;
    }
};